package com.fy.fyspace.model.enums.file;

import java.util.Calendar;
import java.util.Date;

public enum ExpireTimeEnum {
    ONE_DAY(0, 1, "1天"),
    SEVEN_DAYS(1, 7, "7天"),
    THIRTY_DAYS(2, 30, "30天"),
    FOREVER(3, -1, "永久有效");

    private Integer type;
    private Integer days;
    private String desc;

    ExpireTimeEnum(Integer type, Integer days, String desc) {
        this.type = type;
        this.days = days;
        this.desc = desc;
    }

    public Integer getType() {
        return type;
    }

    public Integer getDays() {
        return days;
    }

    public String getDesc() {
        return desc;
    }

    public static ExpireTimeEnum getByType(Integer type) {
        for (ExpireTimeEnum item : ExpireTimeEnum.values()) {
            if (item.getType().equals(type)) {
                return item;
            }
        }
        return null;
    }

    public static Date getExpireTimeByType(Integer type) {
        ExpireTimeEnum expireTime = getByType(type);
        if (expireTime == null || expireTime == FOREVER) {
            return null;
        }

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, expireTime.getDays());
        return calendar.getTime();
    }

    public static String getDateStringByDays(Integer type) {
        ExpireTimeEnum expireTime = getByType(type);
        if (expireTime == null) {
            throw new IllegalArgumentException("Invalid expire time type: " + type);
        }
        return expireTime.getDesc();
    }
}